package com.yizhuoyan.his.webapi.controller.pharmacyoperator;

import com.yizhuoyan.his.ao.CaseRegistrationRecordAo;
import com.yizhuoyan.his.dto.JSONResponse;
import com.yizhuoyan.his.entity.CaseRegistrationRecordEntity;
import com.yizhuoyan.his.entity.DocHerbalPrescriptionDetailEntity;
import com.yizhuoyan.his.entity.DocPrescriptionDetailEntity;
import com.yizhuoyan.his.entity.HosDrugsEntity;
import com.yizhuoyan.his.qco.CaseRegistrationRecordQco;
import com.yizhuoyan.his.service.pharmacyoperator.DrugSendService;
import com.yizhuoyan.his.webapi.controller.pharmacyoperator.vo.CaseRegistrationRecordVo;
import com.yizhuoyan.his.webapi.controller.pharmacyoperator.vo.DocHerbalPrescriptionDetailVo;
import com.yizhuoyan.his.webapi.controller.pharmacyoperator.vo.DocPrescriptionDetailVo;
import com.yizhuoyan.his.webapi.controller.pharmacyoperator.vo.DrugManageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api")
public class SendDrugController {
    @Autowired
    DrugSendService service;
    @GetMapping("/queryRecord")
    public JSONResponse queryCaseRegistrationRecord(CaseRegistrationRecordAo ao)throws Exception{
        CaseRegistrationRecordQco qco = CaseRegistrationRecordQco.of(ao);
        List<CaseRegistrationRecordEntity> caseRegistrationRecordEntities = service.queryCaseRegistrationRecord(qco);
        List<CaseRegistrationRecordVo> list = new ArrayList<>(caseRegistrationRecordEntities.size());
        for(CaseRegistrationRecordEntity entity :caseRegistrationRecordEntities){
            CaseRegistrationRecordVo vo = CaseRegistrationRecordVo.of(entity);
            list.add(vo);
        }
        return JSONResponse.ok(list);
    }
    @GetMapping("/queryHerbalPrescriptionDetails/{id}")
    public JSONResponse queryHerbalPrescriptionDetails(@PathVariable Long id)throws  Exception{
        List<DocHerbalPrescriptionDetailEntity> docHerbalPrescriptionDetailEntities = service.queryHerbalPrescriptionDetails(id);
        List<DocHerbalPrescriptionDetailVo> list = new ArrayList<>(docHerbalPrescriptionDetailEntities.size());
        for(DocHerbalPrescriptionDetailEntity entity: docHerbalPrescriptionDetailEntities ){
            DocHerbalPrescriptionDetailVo vo = DocHerbalPrescriptionDetailVo.of(entity);
            list.add(vo);
        }
        return JSONResponse.ok(list);
    }
    @GetMapping("/queryPrescriptionDetails/{id}")
    public JSONResponse queryPrescriptionDetails (@PathVariable Long id)throws  Exception{
        List<DocPrescriptionDetailEntity> docPrescriptionDetailEntities = service.queryPrescriptionDetails(id);
        List<DocPrescriptionDetailVo> list = new ArrayList<>(docPrescriptionDetailEntities.size());
        for(DocPrescriptionDetailEntity entity : docPrescriptionDetailEntities){
            DocPrescriptionDetailVo of = DocPrescriptionDetailVo.of(entity);
            list.add(of);
        }
        return  JSONResponse.ok(list);
    }
    @GetMapping("/queryHerbalPrescriptionDetailsDrugs/{id}")
    public JSONResponse queryHerbalPrescriptionDetailsDrugs(@PathVariable Long id ) throws Exception{
        List<HosDrugsEntity> hosDrugsEntities = service.queryHerbalPrescriptionDetailsDrugs(id);
        List<DrugManageVo> list = new ArrayList<>(hosDrugsEntities.size());
        for(HosDrugsEntity entity : hosDrugsEntities){
            DrugManageVo of = DrugManageVo.of(entity);
            list.add(of);
        }
        return  JSONResponse.ok(list);
    }
    @GetMapping("/queryPrescriptionDetailsDrugs/{id}")
    public JSONResponse queryPrescriptionDetailsDrugs(@PathVariable Long id) throws Exception{
        List<HosDrugsEntity> hosDrugsEntities = service.queryPrescriptionDetailsDrugs(id);
        List<DrugManageVo> list = new ArrayList<>(hosDrugsEntities.size());
        for(HosDrugsEntity entity : hosDrugsEntities){
            DrugManageVo of = DrugManageVo.of(entity);
            list.add(of);
        }
        return  JSONResponse.ok(list);
    }
}
